import configparser


def config(section: str) -> dict:
    """获取指定类型的配置块，返回字典类型的键值对参数"""
    f = 'app.cfg'
    # 创建配置文件对象
    con = configparser.ConfigParser()

    # 读取文件
    con.read(f, encoding='utf-8')

    # 获取所有section
    sections = con.sections()
    # ['db','xls']

    # 获取特定section
    try:
        items = con.items(section)  # 返回结果为元组
    except configparser.NoSectionError as e:
        print("exception:", e)
    else:
        # 可以通过dict方法转换为字典
        dict_items = dict(items)
        for k, v in dict_items.items():
            dict_items[k] = int(v) if str.isdigit(v) else v
        return dict_items


if __name__ == '__main__':
    print(config("db"))
